<?php include_once '/../Controllers/LayoutController.php';?>
<?php
	if(isset($_GET['request'])){
		$json =  $_GET['request'];
		$requestJson = json_decode($json,true);
		$pageID= $requestJson['getpageconfig'][DBConsts::$PAGEID];
		if($pageID !='' && is_string($pageID)){
			$allJson = array();
			
			//add pageID into json string
			$allJson = array_merge($allJson, array(DBConsts::$PAGEID=>$pageID));
			
			//4. Get page title from 'page_site_map' table by PAGE_ID
			$pageTitle=LayoutController::getPageTitle($pageID);
			if($pageTitle != ''){
				$allJson = array_merge($allJson, array(DBConsts::$PAGETITLE=>$pageTitle['page_title']));
			}
			
			//1. Get logo image from 'moori_config' table
			$arrayMooriConfig = array();
			$logo=LayoutController::getMooriConfig(DBConsts::$LOGO);
			if($logo != ''){
				$array = array(DBConsts::$LOGO=>$logo['value']);
				$arrayMooriConfig = array_merge($arrayMooriConfig, $array);
			}
			
			//7. Get contact information from 'moori_config'
			$contactinfo=LayoutController::getMooriConfig(DBConsts::$CONTACTINFO);
			if($contactinfo != ''){
				$array = array(DBConsts::$CONTACTINFO=>$contactinfo['value']);
				$arrayMooriConfig = array_merge($arrayMooriConfig, $array);
			}
			
			//8. Get footer from 'moori_config' table
			$footer=LayoutController::getMooriConfig(DBConsts::$FOOTER);
			if($footer != ''){
				$array = array(DBConsts::$FOOTER=>$footer['value']);
				$arrayMooriConfig = array_merge($arrayMooriConfig, $array);
			}
			
			$allJson = array_merge($allJson, array(DBConsts::$MOORICONFIGS=>$arrayMooriConfig));
			
			//2. Get links from 'page_top_links'
			$lstPageTopLinks=LayoutController::getTopLinks($pageID, "1");
			if($lstPageTopLinks != ''){
				$lstArrayJson = array();
				foreach ($lstPageTopLinks as $item){
					$array = array("id"=>$item['id'],"text"=>$item['text'], "page_id"=>$item['page_id']);
					array_push($lstArrayJson, $array);
				}
				$allJson = array_merge($allJson, array(DBConsts::$TOPLINKS=>$lstArrayJson));
			}
			
			//3. Get menu from 'page_menu' table
			$lstMenus=LayoutController::getMenus('1');
			if($lstMenus != ''){
				$allJson = array_merge($allJson, array(DBConsts::$MENUS=>$lstMenus));
			}
			
			//5. Get page path from 'page_site_map' table by PAGE_ID
			$lstArrayJson=LayoutController::getPagePath($pageID);
			if($lstArrayJson != ''){
				$allJson = array_merge($allJson, array(DBConsts::$PAGEPATH=>$lstArrayJson));
			}
			
			//6. Get bottom links from 'page_bottom_links' table
			$lstButtomLinks=LayoutController::getButtomLinks('1');
			if($lstButtomLinks != ''){
				$allJson = array_merge($allJson, array(DBConsts::$BOTTOMLINKS=>$lstButtomLinks));
			}
			
			//endcode to json
			header('Content-type: application/json');
			echo json_encode($allJson);
		}
	}
	
?>